package edu.nctu.csie.jichang.dp.behavioral;

import java.util.ArrayList;
import java.util.List;

/**
 * 類似 ap server filter
 * @author Jichang
 */
public class ChainOfResponsibility {

	public static void main(String[] args) {
		FilterChain tChain = new FilterChain();
		tChain.addFilter(new SkipSpaceFilter());
		tChain.addFilter(new SkipUpperCaseFilter());
		String tMsg = "Asd fGH ;";
		System.out.println(tMsg + " => " + tChain.doFilter(tMsg) );
	}
	
}
class FilterChain {
	List<Filter> filters = new ArrayList<Filter>();
	public FilterChain addFilter(Filter f) {
		this.filters.add(f);
		return this;
	}
	public String doFilter(String str) {
		String r = str;
		for(Filter f: filters) {
			r = f.doFilter(r);
		}
		return r;
	}
}
interface Filter{
	String doFilter(String pContent);
}
class SkipSpaceFilter implements Filter{
	public String doFilter(String pContent) {
		return pContent.replaceAll(" ", "");
	}
}
class SkipUpperCaseFilter implements Filter{
	public String doFilter(String pContent) {
		return pContent.toLowerCase();
	}
}